import java.util.*;
import java.io.*;



//https://www.nowcoder.com/practice/e7ed657974934a30b2010046536a5372
//牛客代码, 将Practice4改成Main即可

class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException{
        return bf.readLine();
    }

    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
}
class DSU {
    public static int set = 1000000;
    public static int[] farther = new int[set + 1];
    public static int[] size = new int[set + 1];
    public static int[] stack = new int[set + 1];
    public void build(int n){
        for (int i = 1; i <= n; i++) {
            farther[i] = i;
            size[i] = 1;
        }
    }
    public int find(int n){
        int t = 0;
        while(farther[n] != n){
            stack[t++] = n;
            n = farther[n];
        }
        while(t != 0){
            farther[stack[--t]] = n;
        }
        return n;
    }
    public boolean isSameSet(int a, int b){
        return find(a) == find(b);
    }


    public void union(int a,int b){
        int fa = find(a);
        int fb = find(b);
        if(fa != fb){
            if(size[fa] < size[fb]){
                farther[fa] = fb;
                size[fb] += size[fa];
            }else{
                farther[fb] = fa;
                size[fa] += size[fb];
            }
        }
    }
}

public class Practice4 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read sc = new Read();
    public static void main(String[] args) throws IOException {

        int n = sc.nextInt();
        int k = sc.nextInt();
        DSU dsu = new DSU();
        dsu.build(n);
        while(k-- > 0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if(a == 1){
                if(dsu.isSameSet(b,c)){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }else{
                dsu.union(b,c);
            }
        }


























    }
}